'use strict';

var fs = require('fs'),
  debug = require('debug'),
  log = debug('yozh:config:log'),
  error = debug('yozh:config:error'),
  verbose = debug('yozh:config:verbose');

var config = {
  // https server key
  serverKey: {
    key: fs.readFileSync('./server-key.pem'),
    cert: fs.readFileSync('./server-cert.pem')
  },
  // wechat sercret key
  weChat: {
    appid: 'wx11f5735ab83019e4',
    appsecret: 'c3283bdf5359a4e8821b431f138d542c',
    token: 'youzhe',
    encodingAESKey: 'Rgra7LizLLVhk8ruwrwQF0ByYdxSgPmAff0035uusJQ'
  },
  // wechat accesstoken redis key
  weChatAccessToken: 'weChatAccessToken',
  // koa-xml module config
  koaxml: {
    normalize: true,
    firstCharLowerCase: true,
    explicitArray: false,
    ignoreAttrs: true
  },
  // mode
  debug: true,
  // mongodb db link
  db: 'mongodb://127.0.0.1/youzhe_demo',
  // json web token secret key
  secret: 'youzhe',
  // secretFile: fs.readFileSync('./youzhe.key'),
  // hmac encrypt key
  hmacKey: 'youzhe',
  // md5 mark
  md5: 'md5',
  // sha1 mark
  sha1: 'sha1',
  // webot module rule pattern key
  rulePrefix: '##',
  // redis pw
  redisPw: 'youzhe',
  // get request url cache, like: GET/v1/users
  urlCache: {
    port: 6379,
    host: '127.0.0.1',
    defaultCacheTime: 60*6,
    defaultExpireTime: 60*6,
    options: {
      db: 0
    }
  },
  // token cache, save the json web token, form token, verification token(phone
  //  and email), wechat token.
  tokenCache: {
    port: 6379,
    host: '127.0.0.1',
    pwd: 'youzhe',
    defaultCacheTime: 60*6,
    defaultExpireTime: 60*6,
    options: {
      db: 1
    }
  },
  // webot module session cache
  sessionCache: {
    port: 6379,
    host: '127.0.0.1',
    pwd: 'youzhe',
    defaultCacheTime: 60*6,
    defaultExpireTime: 60*6,
    options: {
      db: 2
    }
  },
  // error information cache
  errorsCache: {
    port: 6379,
    host: '127.0.0.1',
    pwd: 'youzhe',
    defaultCacheTime: 60*6,
    defaultExpireTime: 60*6,
    options: {
      db: 3
    }
  },
  // limit phone codes time
  limitCache: {
    port: 6379,
    host: '127.0.0.1',
    pwd: 'youzhe',
    defaultCacheTime: 60*6,
    defaultExpireTime: 60*6,
    options: {
      db: 4
    }
  },
  // module name
  constants: {
    article: 'articles',
    base: 'bases',
    log: 'logs',
    menu: 'menus',
    operator: 'operators',
    part: 'parts',
    relation: 'relations',
    role: 'roles',
    topic: 'topics',
    user: 'users',
    formToken: 'formtokens',
    authorization: 'authorizations',
    restoration: 'restorations'
  },
  // token state
  tokenState: {
    inactivity: 0,
    activity: 1
  },
  // custom response code
  code: {

  },
  // router prefix
  routerPrefix: {
    v1: {
      users: '/v1/users',
      authorizations: '/v1/authorizations',
      restorations: '/v1/restorations',
      formtokens: '/v1/formtokens'
    }
  },
  codesConf: {
    sid: 'b58acaddda7843278e42fd942bd243b5',
    token: '9425950bc831487b9e1d0b292e5bca19',
    url: 'https://api.qingmayun.com',
    emailSmsUrl: '/SMS/emailSMS',
    appId: '045a1dd061374999a8cd94b3aa09e405',
    emailTemplateId: '3840228',
    softVersion: '20141029',
    softVersionForHttps: '20150822'
  },
  codesLimit: 2
};
config.skipPath = config.routerPrefix.v1.authorizations +
  ',' +
  config.routerPrefix.v1.restorations +
  ',' +
  config.routerPrefix.v1.formtokens
  ;

if (process.env.NODE_ENV === 'test') {
  config.db = 'mongodb://127.0.0.1/youzhe_test';
} else if (process.env.NODE_ENV === 'dev') {
  config.db = 'mongodb://127.0.0.1/youzhe_dev';
} else if (process.env.NODE_ENV === 'produce') {
  config.db = 'mongodb://127.0.0.1/youzhe';
  config.urlCache.defaultExpireTime = 60*60*24*30;
  config.urlCache.defaultCacheTime = 60*60*24*30;
  config.urlCache.options.password = config.redisPw;
  config.tokenCache.defaultExpireTime = 60*60*24*30;
  config.tokenCache.defaultCacheTime = 60*60*24*30;
  config.tokenCache.options.password = config.redisPw;
  config.sessionCache.defaultExpireTime = 60*60*24*30;
  config.sessionCache.defaultCacheTime = 60*60*24*30;
  config.sessionCache.options.password = config.redisPw;
  config.errorsCache.defaultExpireTime = 60*60*24*30;
  config.errorsCache.defaultCacheTime = 60*60*24*30;
  config.errorsCache.options.password = config.redisPw;
  config.limitCache.defaultExpireTime = 60*60*24*30;
  config.limitCache.defaultCacheTime = 60*60*24*30;
  config.limitCache.options.password = config.redisPw;
}

module.exports = config;
